home *** CD-ROM | disk | FTP | other *** search
- Path: pegasus.montclair.edu!harmon
- From: harmon@pegasus.montclair.edu (Derek Harmon)
- Newsgroups: comp.lang.c
- Subject: Re: Solaris -> Windows & byte swapping
- Date: 15 Feb 1996 01:21:54 -0500
- Organization: Montclair State University
- Message-ID: <harmon.824364410@pegasus.montclair.edu>
- References: <4fsk3l$lab@due.unit.no>
- NNTP-Posting-Host: pegasus.montclair.edu
- X-Newsreader: NN version 6.5.0 #68 (NOV)
-
- Vidar Moe <vidarm@ibt.unit.no> writes:
-
- >I have transferred some binary datafiles from Solaris to my PC
- >using ftp with the binary file transfer.
-
- The PC is certainly little-endian, whereas I can't know for certain
- what the Solaris machine is (endian-ism is an aspect of hardware platform),
- my experience with SPARCs has been big-endian, so as you suggest, you pro-
- bably have a conflict here.
-
- > fread(buffer, sizeof(unsigned char), dim, mImageFile);
-
- >and then I process the bytes in the buffer further (my task is
- >to convert a 12 bit image into an 8 bit image, and my problem
- >is basically that the 12 bits belonging to each pixel is
- >organized differently in the buffer under Windows than under
- >Solaris!)
-
- It would help to read in more manageable chunks. Say you want to convert
- from a 12-bit word to an 8-bit word, by reading in 8-bits at a time, you are
- loading either 1 1/2 or 2/3rds (depending on your perspective) at a time.
- The way to do this is by reading in a chunk size that's the least common
- factor. For 8 and 12, that is 24.
-
- When you read in 24-bit chunks, you have 2 well-defined 12-bit words and
- in your case can more easily process these to be 2 well-defined 8-bit words.
- Take a 24-bit chunk-size, then process the first byte and high nybble of
- the second byte to become your first 8-bit word, and the low nybble of the
- second byte and third byte becomes your second 8-bit word.
-
- -- Stone
- --
- # Derek Harmon (aka Stonelight) harmon@pegasus.montclair.edu
- # - Computer Science Undergrad, Montclair State University, NJ
- # - My views are my own, nobody else is this creative. 3;)>
- ... "There is no reason anyone would want a computer in their home." - DEC '77
-
-